
public class MyBinarySearchTree<S extends Comparable<? super S>> implements BinarySearchTree<S > {
	public int contador=0;
	private S element;
	private MyBinarySearchTree<S> left;
	private MyBinarySearchTree<S> right;
	
	private MyBinarySearchTree(S element, MyBinarySearchTree<S> left, MyBinarySearchTree<S> right){
		this.element=element;
		this.left=left;
		this.right=right;
	}
	
	public String toString(){
		return this.recToString();	
	}
	
	private String recToString(){
		String ans="\n\nSoy"+element.toString()+"\n\n<";
		if(left!=null){
			ans+="izq"+left.recToString();
		}
		ans+=" "+element.toString();
		if(right!=null){
			ans+="der"+right.recToString();
		}
		return ans+">";
	}
	
	public MyBinarySearchTree(S ascendentArray[]){
		if(ascendentArray==null){
			return;
		}
		MyBinarySearchTree<S> bst=arrayToTree(ascendentArray,0,ascendentArray.length-1);
		this.element=bst.element;
		this.left=bst.left;
		this.right=bst.right;
	}
	
	private MyBinarySearchTree<S> arrayToTree(S ascArray[], int from, int to){
		if(from<0||from>to){
			return null;
		}
		
		int median=(to+from)/2;
		return new MyBinarySearchTree<S>(ascArray[median], 
					arrayToTree(ascArray,from,median-1),
					arrayToTree(ascArray,median+1,to));
	}

	@Override
	public void add(S key) {
		
	}

	private boolean unbalancedAdd(S key){
		int comp=key.compareTo(element);
		if(comp==0){
			return false;
		}
		if(comp<0){
			if(left==null){
				left=new MyBinarySearchTree<S>(key,null,null);
				return true;
			}
			if(left.unbalancedAdd(key)){
				
			}
		}
		if(right==null){
			right=new MyBinarySearchTree<S>(key,null,null);
			return true;
		}
		if(right.unbalancedAdd(key)){
			
		}
	}
	
	@Override
	public void remove(S key) {
		// TODO Auto-generated method stub
		
	}

	private MyBinarySearchTree<S> get(S key){
		int comp=key.compareTo(element);
		if(comp==0){
			return this;
		}
		if(comp<0){
			if(left==null){
				return null;
			}
			return left.get(key);
		}
		if(right==null){
			return null;
		}
		return right.get(key);
	}
	
	@Override
	public boolean contains(S key) {
		return get(key)!=null;
	}

	@Override
	public int size() {
		// TODO Auto-generated method stub
		return 0;
	}
}
